home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Medal Software 3
/
Gold Medal Software - Volume 3 (Gold Medal) (1994).iso
/
prog
/
pbasmlib.arj
/
SOUND.DOC
< prev
next >
Wrap
Text File
|
1994-02-12
|
40KB
|
843 lines
PBASMLIB Soundblaster/Adlib Module
(C) Copyright 1994 by Tim Gerchmez
All Rights Reserved.
Soundblaster is a trademark of Creative Labs
Adlib/Ad Lib is a trademark of Ad Lib, Inc.
All other software and hardware mentioned herein is owned and
copyrighted by its respective companies.
The Sound Module lets you play music, sound effects, digital samples and
synthesized speech from BASIC on the Soundblaster card. It also lets you
record from the Soundblaster's Microphone or Line Inputs, and play back the
recorded data. The routines in this module will be immediately accessible
to your PB programs by including the statements $INCLUDE "PBASMLIB.INC" and
$LINK "PBASMLIB.PBL" at the top of your programs. These routines are usable
with the PC-AT and compatibles or better, and may not work correctly with
the PC-XT. Many of the routines DO NOT require a driver to be loaded before
using them. The syntax of each routine is explained in the section below,
after the quick reference section (which follows).
Special note: These routines are not compatible with the POW! Soundblaster
library for PowerBASIC, also released by PBASMLIB's author. If you use
POW! in addition to PBASMLIB, you should remove the SOUND module DECLARE
statements in PBASMLIB.INC, as the POW! library commands are a superset of
the commands available in PBASMLIB's Sound module.
PBASMLIB Sound Module Quick Reference
-------------------------------------
Digitized I/O and Related Routines (internal):
----------------------------------------------
-----------------------------------------------
SBPLAYFILE: Plays back a file containing raw sample data
SBPLAYSTRING: Plays back a string containing raw sample data
-----------------------------------------------
SBSAMPLE$: Records a sample from the SB's Line/Mic Inputs
into a string
SBSAMPLEBYTE: Records a single byte from the SB's Line/Mic
Inputs
-----------------------------------------------
-----------------------------------------------
SBRESET: Resets the SB card, preparing for digitized I/O
SBSETBASE: Sets the base port for the SB card (0220h Default)
------------------------------------------------
(2) FM Music (Adlib-Compatible) and related routines (internal):
------------------------------------------------------------
----------------------------------------
SBFMNOTE: Plays a note on the Soundblaster
SBFMSOUND: Plays a sound on the Soundblaster
SBFMRHYTHM: Plays a rhythm sound on the Soundblaster
SBFMPLAY: Plays music contained in a string
----------------------------------------
SBFMCLEAR: Clears the Soundblaster's FM Music Registers
SBFMPARMS: Sets parameters for the FM Music Channels
SBFMPORTOUT: Outputs directly to the FM Music Registers
SBFMSETPORTS: Sets the FM Music Register addresses
SBFMDETECT: Detects whether an FM Music-Capable (Adlib/SB)
card is present
-----------------------------------------
(3) .CMF FM Music Playback (driver):
--------------------------------
---------------------------------------------
SBCMFDETECT: Checks if the SBFMDRV.COM driver is loaded
SBCMFPLAY: Plays a .CMF file in the background (SBFMDRV.COM)
SBCMFTRANSPOSE: Transpose the pitch of a .CMF file (SBFMDRV.COM)
SBCMFSETSPEED: Changes speed of default CMF file playback (SBFMDRV.COM)
SBCMFCHECK: Checks whether a .CMF file is still playing (SBFMDRV.COM)
SBCMFPAUSE: Pauses playback of a .CMF file (SBFMDRV.COM)
SBCMFRESUME: Resumes playback of a .CMF file (SBFMDRV.COM)
SBCMFCANCEL: Cancels playback of a .CMF file (SBFMDRV.COM)
---------------------------------------------
(5) Speech Synthesis Routines (driver):
-----------------------------------
----------------------------------------------------------
SBSAY: Speaks a string through the SB Speech driver (SBTALKER)
SBSPEECH: Checks to see if the SB Speech driver is loaded (SBTALKER)
----------------------------------------------------------
(6) General SB-Related Routines (internal):
---------------------------------------
---------------------------------------------------------
SBBEEP: Sounds a beep through the Soundblaster's FM
Music Channel
SBDELAY: Delay specified number of milliseconds (used by SB
routines)
SBDETECT: Detects whether a Soundblaster card is present
---------------------------------------------------------
SBPRESETMIXER: Resets the Soundblaster Pro card's mixer chip
(SOUNDBLASTER PRO ONLY)
SBPSETMIXER: Sets the Soundblaster Pro's mixer chip settings
(SOUNDBLASTER PRO ONLY)
---------------------------------------------------------
================================================================================
sub sbbeep
Plays a BEEP through the soundblaster. This is one of the "highest
level" routines in the Sound module, requiring no parameters at all.
Similar to the BEEP statement, but plays through the SB's speakers
rather than the PC speaker. You don't even have to detect if an SB
card is present, as SBBEEP does this for you, and plays a normal BEEP
through the PC speaker if not!
Example: sbbeep [or] call sbbeep
================================================================================
sub sbcmfcancel
Cancels (stops) playback of a .CMF file originally started with
SBCMFPLAY. You can then use SBCMFPLAY again to restart the song
from the beginning, if desired.
Example: call sbcmfcancel
================================================================================
function sbcmfcheck
Checks whether a .CMF file is still playing (SBFMDRV.COM),
and returns nonzero if yes, or zero if not. Use with
SBCMFPLAY to determine status of playing file.
Example: print sbcmfcheck
================================================================================
function sbcmfdetect
Detects whether the FM Music Driver (SBFMDRV.COM) for the
Soundblaster card is installed. Returns 0 if not, or IRQ
number (&h80-&hbf) if it is. You should use this before
calling any of the other SBCMF commands to determine whether
the driver was loaded.
Example: print sbcmfdetect
================================================================================
sub sbcmfpause
Pauses a currently playing .CMF song (that you started with
SBCMFPLAY). You can use SBCMFRESUME to continue playback.
Example: call sbcmfpause
================================================================================
sub sbcmfplay(f$,ary%(1))
Plays a .CMF file in the background, using the SBFMDRV.COM driver.
You should pass this routine a 64K integer array to hold the CMF
music data, and the CMF files you select should be less than 64K
in size. You do not have to check for the SBFMDRV.COM being installed
if you don't want to ; this routine does it automatically, and will
terminate if the driver is not installed. If a song is already playing
when this function is called, it will be ended and a new song started.
f$: Set to path\filename of .CMF file to play
ary%(1): Set to the first element of a 64K integer array
(see example below). Array can be shorter than 64K
if you're sure that the size of the CMF file is less
(you can open for binary access and use the LOF function
to determine the length of a file). If you forget to
DIMension the array, or DIM it to too small a size, memory
will be corrupted when the .CMF file loads.
Example: 'SBFMDRV.COM should already be loaded (can be loaded high using
'the DOS 5+ LH or LOADHIGH command.
DIM cmfary%(1:32767) '64K integer array to hold .CMF data
call sbcmfplay "test.cmf",cmfary%(1) 'Play the file
You can use SBCMFCHECK to determine whether the piece is still playing
or has finished (see SBCMFCHECK for details).
================================================================================
sub sbcmfresume
Resumes playback of a song after pausing it with the
SBCMFPAUSE command.
Example: call sbcmfresume
================================================================================
sub sbcmfsetspeed(s%)
Changes the SBFMDRV.COM driver clock rate. This rate is specified
in each .CMF file, and determines the speed the .CMF file will be
played back. Using a positive value for this function will increase
the default value read from a file and passed to the CMF driver by the
specified amount, and using a negative value will decrease the default.
This function can either be used with a CURRENTLY PLAYING .CMF file (to
slow it down or speed it up), or can be used before a file is played to
change the speed at which the next file will be played back. Using a
value of 0 will set the SBFMDRV.COM speed back to the default rates.
Example:
sbcmfsetspeed -8 'Slow down all .CMF files by 8 Cycles
sbcmfplay "test.cmf",ary%(1) 'Plays back .CMF file slower than normal
do:loop until sbcmfcheck=0 'Wait til song is over
sbcmfsetspeed 0 'Returns playback speed to default
================================================================================
sub sbcmftranspose(nm%)
Transposes the pitch of a piece of music up or down by
a particular number of half-tone steps. Use this command
either before playing a .CMF file or during playback to
change the base pitch of the music.
nm%: Set to number of half-tone steps to transpose. A
positive value will transpose up, while a negative
value will transpose down. Using a value of zero
will turn transposing off and set the tone of the
music back to the original.
Example: sbcmftranspose -4 'Transpose 4 steps down
================================================================================
sub sbdelay(ms%)
Pauses the specified number of milliseconds.
ms%: Set to milliseconds (thousandths of a second) to pause.
(0-32767). Max is about 32 seconds.
Example: sbdelay 1000 'Delay one second exactly (hardware-independent).
================================================================================
function sbdetect
Detects whether a Soundblaster or compatible card is installed,
and returns -1 if yes or 0 if no. You should use this routine
before calling any Digital (sampling) I/O functions in this library.
Use SBFMDETECT instead before calling FM Music-related routines, as
the Adlib card will return a not-installed status with this routine
(it's not upward compatible with the Soundblaster). Note: This
routine also RESETS the SB card, and can be used in lieu of SBRESET
if desired.
Example: d% = sbdetect
================================================================================
sub sbfmclear
Clears and initializes the soundblaster's FM music registers.
Use this to (1) stop a sound, (2) before playing sounds to clear
previous values. Returns all internal FM Music settings
to default values. To reset the soundblaster hardware, use
SBRESET instead (this command just clears the FM Music Adlib-
compatible registers).
Example: call sbfmclear
================================================================================
function sbfmdetect
Detects if an Adlib/FM Music-Capable card is installed, and returns
-1 if yes or 0 if no. This routine will return -1 for the Soundblaster,
as it's fully compatible with the Adlib card. Call this before calling any
of the other FM-Music related routines to determine if an appropriate sound
card is installed. Use SBDETECT instead to check for the Soundblaster card
specifically (for digital I/O and related functions).
Example: print sbfmdetect
================================================================================
sub sbfmnote (ch%,fr%,oc%,ad%,sr%,wv%,dly%)
Play a note on the soundblaster using the specified FM music
channel and the specified values (see below). This is the
one of the "lower level" FM Music commands in the Sound Module,
and it gives you a lot of control over parameters. For a higher-
level command that requires less parameters, see SBFMSOUND.
ch%: Set to Soundblaster Melody Channel (voice) (1-9).
fr%: Set to frequency (pitch) (0-1023). The approximate
frequency values for a scale are:
C: 345 C#: 366 D: 388 D#: 409 E: 431
F: 458 F#: 486 G: 515 G#: 545 A: 579
A#: 614 B: 650 C: 688
oc%: Set to octave (0-7) (Controls pitch)
ad%: Set to Attack/Decay (AD) value:
Attack: Bits 4-7 (0=slowest) (0-15)
Decay : Bits 0-3 (0=slowest) (0-15)
Formula: ad% = 16 * attack + decay
attack = ad% \ 16
decay = ad% and 15
sr%: Set to Sustain/Release (SR) value:
Sustain: Bits 4-7 (0=loudest) (0-15)
Release: Bits 0-3 (0=slowest) (0-15)
Formula: sr% = 16 * sustain + release
sustain = sr% \ 16
release = sr% and 15
wv%: Set to waveform (controls sharpness of tone).
0-3, where 0="softest" and 3="sharpest."
dly%: Set to delay value (in milliseconds) (0-32767, or about
32 seconds max). For a delay of zero, routine will play
note and immediately return without "turning note off" -
this is appropriate for certain AD and SR values (see
example below). If a delay is specified, the routine will
play the note ("key on"), delay the specified time, then
turn the note off ("key off").
Example: sbfmnote 1,345,5,240,4,1,0 'Play a note on the Soundblaster
================================================================================
sub sbfmparms(ch%,am%,vb%,sus%,hm%)
Sets extra parameters for a particular SB FM music channel
that will be used with the other SBFM commands (except SBFMPLAY).
This allows you to "fine-tune" the sound of each channel.
These parameters will remain in effect until you do an SBFMCLEAR
or change the soundblaster's registers directly.
Note: SBBEEP uses channel 1, and can be a way to quickly test
new parameter values. Simply call SBFMPARMS followed by an
SBBEEP statement to hear the changes. SBFMCLEAR resets all
values set by SBFMPARMS.
ch%: Set to Soundblaster channel (1-9) to set parameters for
am%: Set to 1 for Amplitude Modulation (tremolo), or 0 for none.
The default value is 0.
vb%: Set to 1 for Vibrato, or 0 for none. The default value
is 0.
sus%: Set to 1 for Note Sustain, or 0 for none. The default
is 0 (no sustain, note decays on SR phase).
hm%: Set to 0-15 to control which harmonic the specified channel
is modulated with. This controls the overall pitch and
tinniness of the output for the specified channel. The
default for this setting is zero.
Example: call sbfmparms(1,0,1,0,0) 'Set vibrato for channel 1
sbbeep 'Hear the vibrato
================================================================================
sub sbfmplay(m$)
Plays music on the Soundblaster - a mini music interpreter, similar
to PB's PLAY command, but works with the soundblaster rather than the
PC speaker, uses different parameters, and is much more flexible. All
SBFMPLAY commands are 2 characters in length (no exceptions), and these
commands are detailed below. The string you send is checked for an even
number of characters (as each command is two bytes), and SBFMPLAY terminates
if the string is not an even length. See the example sound programs
included with PBASMLIB for examples of SBFMPLAY syntax. When building strings
for SBFMPLAY, it is suggested that you do it in layers - add the notes, rests
and octave notations first, then add the chords and other commands later.
m$: Set to a string of characters indicating musical notes and commands
for SBFMPLAY:
a ,a-,a+,b ,b-,b+,c ,c-,c+,d ,d-,d+,e ,e-,e+,f ,f-,f+,g ,g-,g+
A ,A-,A+,B ,B-,B+,C ,C-,C+,D ,D-,D+,E ,E-,E+,F ,F-,F+,G ,G-,G+
Musical notes in SBFMPLAY are indicated by the note letter (the regular
scale CDEFGAB), followed by a space (regular note), a minus (flat), or
a plus (sharp). You can substitute the "b" character for the minus and
the "#" for the plus, if desired. Each note indicated is ALWAYS two
characters long. Using LOWERCASE letters for notes will produce a delay
between each note, while using UPPERCASE letters will play a note and
proceed immediately to the next note (useful for polyphonic music). The
note letters are the only place SBFMPLAY is case-sensitive. The following
are valid strings of notes:
"a a#b b#c c#d d#" <- Notice each note is EXACTLY two characters. Regular
notes (not flat or sharp) can be followed by ANY
character, whereas flats are followed by "-" or
"b", and sharps are followed by "+" or "#".
"C DbE F#G A#B c d e f#g-a+b-c+" <- the first part will be played without
delays between notes. This string is
read C, D flat, E, F sharp, G, A sharp,
B, C, D, E, F sharp, G flat, A sharp,
B flat, C sharp.
See the "O" (Octave) command for further control of note pitch.
------------------------------------------------------------------------------------
h0,h1,h2,h3,h4,h5,h6,h7,h8,h9,ha,hb,hc,
hd,he,hf,hg,hh,hi,hj,hk,hl,hm,hn,ho (upper or lowercase):
The "h" command plays a CHORD. All standard 3-voice major and minor
sharp and flat chords are supported in SBFMPLAY. 7th chords and others
are not currently supported. Voices 4-6 of the Soundblaster are used
for chords, so if you use them, v1-3 and v7-9 are free for the melody
(rhythm uses v7-9 - see the "X" command). The following "h" (the H may
be capitalized) commands correspond to the following chords:
h0: C h4: G h8: Dm hc: Am hg: F#/Gb hk: D#m/Ebm
h1: D h5: A h9: Em hd: Bm hh: G#/Ab hl: F#m/Gbm
h2: E h6: B ha: Fm he: C#/Db hi: A#/Bb hm: G#m/Abm
h3: F h7: Cm hb: Gm hf: D#/Eb hj: C#m/Dbm hn: A#m/Bbm
ho: silence chord
All chord commands are two characters, as are all note commands.
To cause chords to sustain, rather than play once, use the "N" command.
------------------------------------------------------------------------------------
i0,i1,i2,i3 (upper or lowercase):
"I" sets vIbrato (rapid variation of frequency) and tremolo (rapid
variation of volume) on and off. Use I1 to turn vibrato on for the
current channel (last specified with the V command), I2 to turn
tremolo on, or I3 to turn BOTH vibrato and tremolo on. I0 will
turn off vibrato and/or tremolo for the current channel.
------------------------------------------------------------------------------------
n0,n1,n2,n3,n4,n5,n6,n7,n8,n9 (upper or lowercase):
The "N" command controls the eNvelope of the notes in the SBFMPLAY
string. A sound's envelope consists of its attack, decay, sustain
and release (ADSR) phases, which have to do with the changes in
volume of a note during its lifetime. The attack rate is how
quickly the sound rises from zero to full volume. The decay rate
is how fast the note falls off from the attack peak to the sustain
level. The sustain level is the volume the note sustains at until
it's released. The release rate is how quickly the note falls off
from the sustain level to zero volume when released. If all this
is confusing to you, it doesn't matter - the "N" command in SBFMPLAY
lets you choose from some predefined sound envelopes. N0 - N5 are
NOTE envelopes (affecting the A-G note commands), while N6 - N9 are
CHORD envelopes (affecting the H0-Ho commands). The following "N"
commands are predefined:
n0: Note (default) - fast attack, medium release (string sound)
n1: Note - medium attack, slow release (softer sound)
n2: Note - fast attack, fast release (plink sound)
n3: Note - Medium all (ADSR) (medium sound)
n4: Note - Slow attack, slow release ("backward" or "wah wah" sound)
n5: Note - Slow attack, very slow release (soft sustain)
n6: Chord (default) - fast attack, medium release (string sound)
n7: Chord - slow attack, medium release
n8: Chord - slow attack, slow release
n9: Chord - slow attack, no release (sustain chords)
You can use "S" (Sustain notes) in combination with the "N" commands to
fine-tune the envelope of notes. You can also both N values below 5 and
N values above 5 to set both voice and chord envelopes. For example,
"n2n8" is a perfectly valid combination.
------------------------------------------------------------------------------------
o0,o1,o2,o3,o4,o5,o6,o7 (upper or lowercase):
The "O" command changes octaves. For example, you would insert
"o4" in the command string at the right place to change to octave 4.
All subsequent notes will play in that octave until changed with
another "O" command. The octave setting defaults to o5.
-------------------------------------------------------------------------------------
p0,p1,p2,p3,p4,p5,p6,p7,p8,p9 (upper or lowercase):
"P" controls the overall pace of the music (or tempo). The number you
provide is multiplied by 10 and used as a "millisecond base" for delays
in conjunction with the "W" command (described later). The "P" command
controls the actual wait time of the "W" (wait) command. P1, for example,
would provide a millisecond delay base of 0,10,20,30,40,50,60,70,80,90
corresponding to W0 through W9. Contrary to what you might imagine, the
larger the number given, the SLOWER the actual pace will be. The lower
the number, the FASTER the pace.
-------------------------------------------------------------------------------------
q1,q2,q3,q4,q5,q6,q7,q8,q9 (upper or lowercase):
The "Q" command stands for "quiet," and will silence a voice. This is
useful when used with the "S" (sustain) command, to shut off a voice at
will. You provide the number of the channel to silence along with the Q.
For example, "q3" would silence voice (channel) 3.
-------------------------------------------------------------------------------------
r0,r1,r2,r3,r4,r5,r6,r7,r8,r9,r. (upper or lowercase):
The "R" command stands for "Rest." Placing an R in the music string with
a number value will pause for the same amount of time as a corresponding
note would according to the current setting of the "W" command. R0 will
pause no time at all, and R. (r followed by a dot) will pause the same
amount of time as the notes (a normal full rest). The actual wait time
of each rest can be controlled by the "P" command the same way the "W"
command is. You may have to play around to get a feel for the timing of
the "R" command.
-------------------------------------------------------------------------------------
s0,s1 (upper or lowercase):
The "S" command controls note sustain. When set to one, all voices will
be sustained after they are played. When set to 0, the voice will play
for a second and then be silenced (like a guitar string). Simply insert
the Sx command at the desired place in the command string. Sustain applies
to "regular" notes only - to set chord sustain, use the "N" command (N9) to
set an envelope for chords that supports a sustain effect. Use the "N" and
the "S" commands together to control the ENVELOPE of the notes played (see
the "N" command for an explanation). For those who've already read that
section, the "S" command sets the SUSTAIN of notes to high and the RELEASE
value to 0 (no release) if turned on, or 4 (medium release) if turned off.
Using "S" does not affect the attack/decay portion of the note envelope.
-------------------------------------------------------------------------------------
t0,t1,t2,t3 (upper or lowercase):
The "T" command controls the TONE of the music playing. The higher the
number the "sharper" and more string-instrument like the sound will be.
Number parameters can range from 0 (very soft) to 3 (very sharp).
--------------------------------------------------------------------------------------
u0,u1,u2 (upper or lowercase):
The "U" command stands for User, and determines how the user can cancel
the SBFMPLAY command. U0 sets SBFMPLAY to cancel when the user presses
any key (this is the default), U1 sets SBFMPLAY so the user can cancel
the command only with the ESC key, and U2 sets SBFMPLAY so the user cannot
cancel it until the string is done playing. Once again, SBFMPLAY defaults
to allowing the user to cancel by pressing any key on the keyboard (SBFMPLAY
will not cancel in the middle of a rest or other delay, only between notes).
--------------------------------------------------------------------------------------
v1,v2,v3,v4,v5,v6,v7,v8,v9 (upper or lowercase):
"V" controls which voice (channel) of the soundblaster will be used to play all
notes following the command (until the next V command). Provide a channel
number between 1 and 9. For example, "v1C v2E v3G " will play 3 notes, each
note on a different soundblaster channel (note the required space after the final
"G" note).
---------------------------------------------------------------------------------------
w0,w1,w2,w3,w4,w5,w6,w7,w8,w9 (upper or lowercase):
"W" stands for Wait, and controls how long SBFMPLAY will wait after
starting to play a note. If you set the wait value to zero, it will
immediately continue on to the next note (same as if you used a
capital letter to represent the next note). The actual time the "W"
command waits is determined by the "P" (pace) command. Use "W" to
set the overall time between notes, while using "R" to add arbitrary
rests between notes. The "W" wait value defaults to 5 if never set
in the SBFMPLAY string.
----------------------------------------------------------------------------------------
x0,x1,x2,x3,x4,x5,x6,x7,x8,x9 (upper or lowercase):
The "X" command plays a drumbeat or rhythm - think of the letter X
as a pair of crossed drumsticks to help you remember this command.
Each command (X0 through X9) plays a different rhythm sound. Please
listen to these sounds to determine which ones are correct for the
songs you are playing.
Example: SBFMPLAY "x3r4x3r4x3r4x3r4" 'Plays 4 drum beats with rests
'between them
================================================================================
sub sbfmportout(rg%,dat%)
Lets you write directly to the Soundblaster's FM registers,
should you be so inclined. A good book on the Soundblaster
(or the SB Developer's kit) is recommended, as an explanation
of Soundblaster registers is beyond the scope of PBASMLIB's documentation.
This command is for the FM music registers only (normally &h388 and &h389);
it does not work for digitized sound playback. You do not have to include
delays, etc. after writing the ports using this command, as they are built
into the SBFMPORTOUT command.
rg%: Set to register to write to (01h-F5h)
dat%: Set to data to write to register (0-255)
Example: sbfmportout &h60,0 'Set channel 1 Attack/Decay to 0
================================================================================
sub sbfmrhythm(drum%,ad%,sr%,fr%,oc%)
Play a rhythm sound on the soundblaster. FM Melody channels 7-9
are not available when using this command. You'll have to experiment
to find the appropriate parameters for the different types of drum
sounds.
drum%: Set to drum sound desired:
Bit 0 = Hi Hat (add 1)
Bit 1 = Snare (add 2)
Bit 2 = Tom tom (add 4)
Bit 3 = Cymbal (add 8)
Bit 4 = Bass (add 16)
ad%: Set to Attack/Decay (AD) value:
Attack: Bits 4-7 (0=slowest) (0-15)
Decay : Bits 0-3 (0=slowest) (0-15)
Formula: ad% = 16 * attack + decay
attack = ad% \ 16
decay = ad% and 15
sr%: Set to Sustain/Release (SR) value:
Sustain: Bits 4-7 (0=loudest) (0-15)
Release: Bits 0-3 (0=slowest) (0-15)
Formula: sr% = 16 * sustain + release
sustain = sr% \ 16
release = sr% and 15
fr%: Set to frequency (0-1023)
oc%: Set to octave (0-7)
Example: sbfmrhythm 8,240,4,1000,7 'Play a note on the snare drum
================================================================================
sub sbfmsetports(addr%,dat%)
Sets the soundblaster's Address/Status port and
Data port locations. These are the ports for Adlib
compatible FM Music output. It's highly unlikely you'll
need to use this function, as the defaults (&h388
and &h389) are standard Soundblaster/Adlib ports, but
it's included for future compatibility, and in case
an unusual hardware setup presents a problem. See
SBSETBASE for a related function to set the SB base
I/O address for digitized sound output.
addr%: Set to SB Address/Status port (normally &h388)
dat%: Set to SB Data port (normally &h389)
Example: sbfmsetports &h388,&h389 'Set to default values
================================================================================
sub sbfmsound(ch%,fr%,oc%)
Play a note on the Soundblaster using the specified FM sound
channel and the specified values. This is a mid-level function
that gives you less control over SB FM sound parameters than SBFMNOTE
does, but makes it easier to play a note. Routine returns immediately
(no delay between notes). Waveform and ADSR values are preset for
each channel:
Ch 1: Soft sound, fast attack, slow release
Ch 2: Medium sound, fast attack, slow release
Ch 3: Sharp sound, fast attack, slow release
Ch 4: Soft sound, medium attack, medium release
Ch 5: Medium sound, medium attack, medium release
Ch 6: Sharp sound, medium attack, medium release
Ch 7: Soft sound, slow attack, slow release
Ch 8: Medium sound, slow attack, slow release
Ch 9: Sharp sound, slow attack, slow release
ch%: Set to SB sound channel (1-9)
fr%: Set to frequency (pitch value) (0-1023). The
approximate frequency values for a scale are:
C: 345 C#: 366 D: 388 D#: 409 E: 431
F: 458 F#: 486 G: 515 G#: 545 A: 579
A#: 614 B: 650 C: 688
oc%: Set to octave (0-7) (Controls pitch)
Example: sbfmsound 1,409,5 'Play a "D#" on channel 1 in octave 5
================================================================================
sub sbplayfile (f$,dly%)
Plays an uncompressed digitized (raw) sound file through the Soundblaster
in the foreground (processing will not continue until the file is done
playing). A utility is included with PBASMLIB to convert .VOC and .WAV files
to .RAW files that can be played with this routine (MAKERAW.EXE).
NOTE: Use the $STRING metastatement to allocate the maximum size
string segment possible, as the shorter the string, the less of the
file can be read in at once, and the more delays you may hear in the
playback of the file. $STRING 32 is recommended.
f$: Set to the path\filename of the file to play. You should not
attempt to play back .VOC and .WAV files directly with this
routine (convert them to raw sample data with MAKERAW first).
Although it can be done, it will introduce a lot of extra noise
into the samples because of the extra information included in .VOC
and .WAV files (header, block types, etc).
dly%: Set to a delay value, which will vary depending on the
speed the sound file was originally recorded at. Experiment
with this value to find the optimal delay setting for the file(s)
you are playing. The higher the value given, the slower the file
will be played back (the longer the delay).
Example: sbplayfile "test.raw",60 'Play back a .RAW file with delay of 60.
================================================================================
sub sbplaystring(s$,rte%)
Plays back a sample recorded into a string with SBSAMPLE$, and
can also play any raw sample data contained in a string. Similar
to SBPLAYFILE, but plays from a string instead of from a file.
s$: Set to string containing digitized sample data retrieved with
SBSAMPLE$, or from a file containing raw sample data.
rte%: Set to playback rate (see SBSAMPLE$ and SBPLAYFILE for examples
of how the rate value applies to playback speed.
Example: s$=sbsample$(8000,40) 'Record a sample
sbplaystring s$,40 'Play back sample s$ at rate 40
================================================================================
sub sbpresetmixer <SB-PRO ONLY>
Resets the onboard mixer to power-up state on the Soundblaster
Pro card. Probably won't do any harm using the mixer commands with
a regular Soundblaster, but the user should be polled in your program
as to the type of SB card he/she has. See SBPSETMIXER to set the values
of the SB Pro's onboard mixer chip.
Example: call sbpresetmixer
================================================================================
sub sbpsetmixer(ms%,mv%,vfm%,vcd%,vln%,vvc%,vmc%) <SB-PRO ONLY>
Sets values for the Soundblaster Pro's mixer chip. Calling this
routine with a regular Soundblaster probably won't do any harm, but
the user should be polled in your program as to the type of SB card he
or she has. See SBPRESETMIXER to reset the mixer chip to power-up values.
ms%: Set to 0 for mono or 1 for stereo output. This also selects
filtered output automatically.
mv%: Set to master volume setting (0-15) for left and right channels.
The formula to use is 16 * left channel + right channel.
vfm%: Set to volume for FM music (0-15) for left and right channels.
The formula to use is 16 * left channel + right channel.
vcd%: Set to volume for CD output for left and right channels.
The formula to use is 16 * left channel + right channel.
vln%: Set to volume for line in, left and right channels.
The formula to use is 16 * left channel + right channel.
vvc%: Set to volume for digitized sound for left and right channels.
The formula to use is 16 * left channel + right channel.
vmc%: Set to volume for microphone input (0-7).
Example: sbpsetmixer 1,255,255,255,255,255,255 'Stereo, max volume all.
================================================================================
sub sbreset
Resets the Soundblaster card, preparing it for digitized output.
This is similar to the SBFMCLEAR command (which applies to FM music),
but SBRESET should be called before using SBPLAYFILE, SBPLAYSTRING or
SBSAMPLE$ for the first time. You should call it once before outputting
digitized sound with any of the above mentioned commands, and again if you
start using a new command at some point in your program.
Example: call sbreset
================================================================================
function sbsample$(ln%,rte%)
Reads a digital sample from the Soundblaster's Line In or Microphone
Input and stores it in a string. The sample can then be played back with
SBPLAYSTRING, or stored in a file and played back later with SBPLAYFILE.
ln%: Set to length of sample to take. This value should never exceed
the string segment size set with $STRING (see example below). The sample
will be read until the entire sample length you passed in ln% is taken.
rte%: Set to a RATE value, similar to the dly% parameter in SBPLAYFILE.
The higher the value of rte% you provide, the more recording time you'll
get from a given value passed in ln%, but the poorer the sound quality.
I have gotten good results with rte% values from 10 to 50. Lower than
10 will give you very little recording time with few additional benefits,
and the accuracy as related to SBPLAYFILE playback decreases as well (if
you use the same value for rte% in sbsample$ and dly% in sbplayfile).
Values over 50 usually result in poor sound quality.
Example: $string 8 'must be 8 or greater for this example
call sbreset 'Reset the SB
print "Press a key to start recording a sample";
while inkey$="":wend
s$ = sbsample$(8000,40) 'Take an 8000-byte sample at rate 40
open "sample.raw" for output as #1 'Prepare to save the sample
print #1,s$; 'Write sample to file
close #1
print "Press a key to play the sample back"
sleep
sbplayfile "sample.raw",40 'Play back the digital sample.
================================================================================
function sbsamplebyte
Allows you to sample a byte directly from the Soundblaster's Microphone
or Line Input, allowing you to signal your program via voice or sound
input. It also allows experimentation with voice recognition and other
similar ideas.
sbsamplebyte: Returns the value of the byte most recently sampled from the
SB's Line In or Mic In. This will be 128 for no input, and
a varying other value depending on the amplitude and the
waveform of the input signal. 128 seems to be the median
value, with values dropping below and climbing above this
number as the waveform of the input signal changes.
Example: call sbreset ;Always recommended before using sbsamplebyte
do
print sbsamplebyte
loop
================================================================================
sub sbsay(s$)
Note: This command will not function in the PB IDE and must be
run within a standalone .EXE file.
Speaks a string as synthesized speech if the SB speech
driver is loaded (check for it with SBSPEECH before calling).
String should be a maximum of 255 characters in length.
Example: sbsay "Hello there!"
================================================================================
sub sbsetbase(io%)
Sets the base address for the Soundblaster card
(normally &h220). This controls output of digitized
sounds (SBPLAYFILE/SBPLAYSTRING commands). To set
the Adlib FM-Music ports, use SBFMSETPORTS instead.
Note: You can often get this address from the BLASTER environment
variable. If you use S$=ENVIRON$("BLASTER"), a string will be
returned in S$ of the form "A220 I7 D1 T3". The A220 indicates
the base address (220 hex), the I7 the interrupt number (7), the D1
the DMA number (1). The T indicates the type of sound card. You can
parse this string out and use SBSETBASE to set the SB's base address
for the PBASMLIB Sound Module (the interrupt, type and DMA values are
not needed by this module).
io%: Set to base I/O port address for the Soundblaster card.
Example: sbsetbase &h220
================================================================================
function sbspeech
Note: This command will not function in the PB IDE and must be
run within a standalone .EXE file.
Returns -1 if the SB's speech driver is installed,
or 0 if not. Use before calling SBSAY to add synthesized
speech to your programs.
Example: print spspeech